{layout name="public/layout" /}
{include file='yxnavbar'}


<div class="main">
    {include file='game/game_common_nav'}
    <div class="panel panel-default" role="tabpanel">
        <div class="panel-heading">游戏关卡设置</div>
        <div class="panel-body">
            <form action="" method="post" class="form-horizontal" role="form" name="form2" id="form2">
                <input type="hidden" name="gl_id" value="{$item['gl_id']}"/>
                <input type="hidden" name="themeid" value="{$themeid}"/>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>当前关卡数：</label>
                    <div class="col-sm-8 col-xs-12">
                        <div class="col-sm-4 col-xs-12 input-group">
                            <span class="input-group-addon">第</span>
                            <input class="form-control" type="number" min="1"  maxlength="2" name="sort" id="sort"  value="{php echo $item['sort'];}">
                            <span class="input-group-addon">关</span>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>关卡完成需要的操作次数</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="number" class="form-control" min="1"   id="type_op_num"  name="type_op_num"  value="{$item['type_op_num']}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label"><span style="color: red;">*</span>关卡操作类型</label>
                    <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
                        <label class="radio-inline">
                            <input name="type" value="share" {if $item['type']=='share' || empty($item['type'])} checked="checked"{/if} type="radio"> 分销
                        </label>
                        <label class="radio-inline">
                            <input name="type" value="friend" {if $item['type']=='friend' } checked="checked"{/if} type="radio">好友到访
                        </label>
                        <label class="radio-inline">
                            <input name="type" value="order" {if $item['type']=='order' } checked="checked"{/if} type="radio">转介绍
                        </label>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label"><span style="color: red;">*</span>回答问题开始关卡</label>
                    <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
                        <label class="radio-inline">
                            <input name="open_question" value="0" {if $item['open_question']==0 || !$item['open_question']} checked="checked"{/if} type="radio"> 否
                        </label>
                        <label class="radio-inline">
                            <input name="open_question" value="1" {if $item['open_question']=='1' } checked="checked"{/if} type="radio">是
                        </label>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label"><span style="color: red;">*</span>绑定奖品：</label>
                    <div class="col-sm-8 col-xs-12">
                        <div class="input-group">
                            <select class="form-control" name="p_id">
                                <option value="0" {if empty($item['p_id']) }selected="selected"{/if}>----------默认不显示----------</option>
                                {loop $box_prizes  $val}
                                <option value="{$val['p_id']}" {if $item['p_id'] == $val['p_id'] }selected="selected"{/if}>{$val['p_id']}-{$val['name']}</option>
                                {/loop}
                            </select>

                        </div>

                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>关卡图标</label>
                    <div class="col-sm-8 col-xs-12">
                        {php echo view_form_field_image('img',$item['icon']);}
                        <span class="help-block">图片尺寸：200*200像素</span>
                    </div>
                </div>
                {if $total>=10}
                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">本关有机会获得奖项</label>
                    <div class="col-sm-10 col-xs-12">
                        {loop $list $row}
                        <label class="radio-inline">
                            <input name="level_sorts[]" type="checkbox" value="{$row['sort']}"
                                   {if (strstr($item['bind_show_sorts'] . ",",$row['sort'] .",")!==false )}
                            checked
                            {/if}
                            > 第{$row['sort']}关-{$row['name']}
                        </label>
                        {/loop}
                    </div>
                </div>
                {/if}

                <div class="form-group" id="sub_upload" >
                    <div class="col-sm-12">
                        <input name="submit" onclick="addOrEditLtItem()" id="btnConfirm" type="button" value="提交" class="btn btn-primary col-lg-2">
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(
        function (){
        }
    );
    function drop_confirm(msg, url){
        if(confirm(msg)){
            window.location = url;
        }
    }
    //新增\修改 提交数据
    function addOrEditLtItem() {
        let postUrl = "{php echo createWebUrl('game',array('op'=>'level_update'));}";
        let success_redirect = "{php echo createWebUrl('game',array('op'=>'level'));}";
        let formData = $("#form2").serialize();
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:formData,
            success:function (e) {
                let res = e.message;
                let code = res.code;
                let msg = res.msg;
                if (code!=200){
                    layer.msg(msg)
                }else{
                    layer.msg(msg);
                    window.location.href = success_redirect;
                }

            },
            fail:function (err) {
                console.log(err)
            }
        })
    }
    // 修改、删除奖品
    function changeOrDelLttInfo(e) {
        let ltt_id = e.getAttribute("data-id");
        let type = e.getAttribute("data-type");
        let themeid = e.getAttribute("data-themeid");
        let redirectUrl = e.getAttribute("data-edit-url");
        let postUrl ="";
        if (type=='edit'){
            window.location.href = redirectUrl;
        }
    }
</script>
